#ifndef __readfile_h__
#define __readfile_h__ 


#include <stdio.h>
#include <stdlib.h>

int readfile(const char *path, char **buf)
{
    FILE *f = fopen(path, "rb");
    if (f == NULL)
        return -1;

    fseek(f, 0, SEEK_END);
    long int len = ftell(f);
    fseek(f, 0, SEEK_SET);

    *buf = malloc(len);
    if (*buf == NULL)
        return -2;

    size_t sz = fread(*buf, 1, len, f);
    fclose(f);

    return (int)sz;
}


#endif

